import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:gzmall_app/common/color_common.dart';
import 'package:gzmall_app/model/product.dart';
import 'package:gzmall_app/common/api.dart';
import 'package:gzmall_app/model/product.dart';

class ProductItemWidget extends StatelessWidget {
  Product clearance;
  double width;
  Function onClickClearance;

  ProductItemWidget(this.clearance, this.width, this.onClickClearance);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onClickClearance,
      child: Container(
        width: width,
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border.all(width: 1.0, color: ColorCommon.black4)),
        child: Stack(
          children: <Widget>[
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                CachedNetworkImage(
                  height: width,
                  width: width,
                  imageUrl: clearance != null && clearance.avatar != null
                      ? clearance.avatar
                      : Api.defaultAvatar,
                  fit: BoxFit.fill,
                ),
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.only(
                        top: 4.0, bottom: 4.0, left: 4.0, right: 4.0),
                    child: Text(
                      clearance?.name ?? "",
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                      style:
                          TextStyle(fontSize: 12.0, color: ColorCommon.black1),
                    ),
                  ),
                ),
                Container(
                  padding: const EdgeInsets.only(left: 4.0, right: 4.0),
                  child: Row(children: <Widget>[
                    Expanded(
                      child: Text(
                        "现价¥" +
                            (clearance?.lowSalePrice != null
                                ? clearance?.lowSalePrice.toString()
                                : "¥0.0"),
                        style:
                            TextStyle(color: ColorCommon.grey8, fontSize: 10.0),
                      ),
                    ),
                    Text(
                      "已售出0件",
                      style:
                          TextStyle(color: ColorCommon.grey8, fontSize: 10.0),
                    ),
                  ]),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
